package com.ysd.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ysd.dao.impl.CompanyDaoImpl;
import com.ysd.dao.impl.ProductDaoImpl;
import com.ysd.dao.impl.SJXWDaoImpl;
import com.ysd.dao.impl.SuiJiTuPianDaoImpl;
import com.ysd.dao.impl.SuiJiXinWenDaoImpl;
import com.ysd.entity.Company;
import com.ysd.entity.Newsdetails;
import com.ysd.entity.Product;

public class HomeServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 调用实现类
		// 公司
		CompanyDaoImpl cDao = new CompanyDaoImpl();
		Company company = cDao.getCompany();
		request.setAttribute("company", company);
		
		// 随机获取几条数据
		SuiJiTuPianDaoImpl sDao = new SuiJiTuPianDaoImpl();
		ArrayList<Product> suiJiList = sDao.getSuiJi();
		request.setAttribute("suiJiList", suiJiList);
		//获取 随机新闻
		SuiJiXinWenDaoImpl sjxwDao=new SuiJiXinWenDaoImpl( );
		List<Newsdetails> sjxwList=sjxwDao. getNewsdetails();
		request.setAttribute("sjxwList", sjxwList);
		
		SJXWDaoImpl sjDao=new SJXWDaoImpl();
		List<Newsdetails> sjList=sjDao.getNewsdetails();
		request.setAttribute("sjList", sjList);
		
		request.getRequestDispatcher("index.jsp").forward(request, response);// 转发
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
